package com.jkoss.action.zx;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.jkoss.biz.zx.zxbiz;
import com.jkoss.pojo.zx.Consultation;
import com.jkoss.tool.Page;

@Controller
@RequestMapping("/zx")
public class ZxXueyuanAction {

	@Autowired
	private zxbiz zbiz;
	@RequestMapping("ShowZxXueyuan.do")
	public String ShowZxXueyuan(HttpServletRequest req ,Page<Consultation> page){
	   
	
		if(page==null){
			page = new Page<Consultation>();
		}
		List<Consultation> listzx =zbiz.Showzxxueyuan(page);

		if(listzx!=null&&listzx.size()>0){
			page.setResults(listzx);
			req.setAttribute("page", page);
		}
		return "listzx.jsp";
	}
	@RequestMapping("addzx.do")
	public String AddZx(Consultation consultation,HttpServletRequest req) {
		
		Date  date = new Date();
		consultation.setContime(date);
		int row =zbiz.addConsultation(consultation);
		
		if(row>0){
			req.setAttribute("msg", "添加成功");
		}else{
			req.setAttribute("msg", "添加失败");
		}
		return ShowZxXueyuan(req,null);
	}
	
	@RequestMapping("toupzx.do")
	public String toupzx(String zstuid ,HttpServletRequest req){
		
		Consultation consultation =zbiz.findzxByOne(zstuid);
		
		if(consultation!=null&&!consultation.equals("")){
			req.setAttribute("consultation", consultation);
		}
		return "upzx.jsp";
	}
	
	@RequestMapping("upzx.do")
	public String upzx(Consultation consultation,HttpServletRequest req){
		
	   int row = zbiz.upzx(consultation);
	   if(row>0){
			req.setAttribute("msg", "修改成功");
		}else{
			req.setAttribute("msg", "修改失败");
	   
	}
	   return ShowZxXueyuan(req,null);
	}
	
	@RequestMapping("delzx.do")
	public String DelZx(Integer zstuid,HttpServletRequest req){
		
		int row =zbiz.delzx(zstuid);
		if(row>0){
			req.setAttribute("msg", "删除成功");
		}else{
			req.setAttribute("msg", "删除失败");
			
		
	}
		return ShowZxXueyuan(req,null);
	}
}
